package com.itheima.dao;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Create By Awen on 2021/8/22
 *
 * @author Awen
 */
public interface UserMapper {
    @Select("select * from user where username=#{username} and password=#{password}")
    User login(User user);

    @Select("select * from t_user where isdelete = 0 limit #{startIndex},#{pageSize}")
    List<User> queryUsersByPage(@Param("startIndex") int startIndex, @Param("pageSize") int pageSize);

    @Select("select count(*) from t_user where isdelete = 0")
    int queryUsersCount();

    @Insert("insert into t_user (username,email,password,remark) values(#{username},#{email},#{password},#{remark})")
    @Options(useGeneratedKeys = true, keyProperty="id", keyColumn="id")
    void addUser(User user);

    @Insert("insert into t_user_role values(#{userId},#{roleId}) ")
    void addUserAndRole(@Param("userId") int userId,@Param("roleId") String roleId);

    @Update("update t_user set username = #{username}, email = #{email}, password = #{password} where id = #{id}")
    void updateUserById(User user);

    @Update("update t_user set isdelete = 1 where id = #{id}")
    void deleteUserById(@Param("id") String id);
}
